package com.sweet.jpa.service;

import com.sweet.jpa.repository.EntityRepository;
import com.sweet.page.Page;
import com.sweet.page.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * 通用业务实现
 *
 * @author limi 2018-04-03-13:46
 */
public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID> {
    @Autowired
    private EntityRepository<T, ID> entityRepository;

    @Override
    @Transactional
    public T insert(T t) {
        return entityRepository.insert(t);
    }

    @Override
    @Transactional
    public T update(T t) {
        return entityRepository.update(t);
    }

    @Override
    @Transactional
    public void delete(T t) {
        entityRepository.remove(t);
    }

    @Override
    public T getOne(ID id) {
        return entityRepository.getById(id);
    }

    @Override
    public int getCount() {
        return entityRepository.getCount();
    }

    @Override
    public List<T> getList() {
        return entityRepository.getAll();
    }

    @Override
    public Page<T> getPage(Pageable pageable) {
        return entityRepository.getAll(pageable);
    }
}